#include "BieuThucChia.h"

BieuThucChia::BieuThucChia()
{
	//this->m_u=null;
	//this->m_v=null;	
}
BieuThucChia::BieuThucChia(BieuThuc *a,BieuThuc *b)
{
	this->m_u=a;
	this->m_v=b;
}
BieuThucChia::~BieuThucChia()
{
}
BieuThuc& BieuThucChia::khoitao(float *x,int i)
{
	this->k=x[i];
	i++;
	this->m_u->khoitao(x,i);
	this->m_v->khoitao(x,i);
	return *this;
}
string BieuThucChia::bieuDien()
{
	return "(" + this->m_u->bieuDien() + ")/(" + this->m_v->bieuDien()+")";
}

string BieuThucChia::bieuDienDaoHam()
{
	return "Not yet implemented";
}

float BieuThucChia::tinhDaoHam(float x)
{
	float giatriv = this->m_v->tinhGiaTri(x);
	if(giatriv==0)
		return 99999;
	return (this->m_u->tinhDaoHam(x)*giatriv - this->m_u->tinhGiaTri(x)*this->m_v->tinhDaoHam(x))
		/ (giatriv * giatriv);
}

float BieuThucChia::tinhGiaTri(float x)
{
	return this->m_u->tinhGiaTri(x)/this->m_v->tinhGiaTri(x);
}